package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/2/29.
 */
@HttpInlet(Conn.InLET_GET_VIOLATION)
public class GetViolation extends JTAsyGet<GetViolation.Info>{

    public String token = JTApplication.jtPreferences.readToken();

    public String obdId = JTApplication.jtPreferences.readOdbID();

    public String engine_code = JTApplication.jtPreferences.readEngineCode();

    public String city_code = "";

    public String platenum = JTApplication.jtPreferences.readPlateNum();

    public String vin_code = JTApplication.jtPreferences.readVincode();

//    public String token = "74PWI719WPA5GY23AURVFBMLOPSQ5Z";
//
//    public String obdId = "1be0dbb519fb12e3";
//
//    public String engine_code = "122901204";
//
//    public String city_code = "";
//
//    public String platenum = "辽B9U687";
//
//    public String vin_code = "LSGLP83X7CF178039";

    public GetViolation(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");



            JSONObject body = apiTYF.optJSONObject("body");

            JSONArray violation = body.optJSONArray("lists");

        if(violation != null){

            for(int i = 0;i<violation.length();i++) {

                JSONObject vio_item = violation.optJSONObject(i);

                Violation mItem = new Violation();

                mItem.AREA = vio_item.optString("area");

                mItem.ACT = vio_item.optString("act");

                mItem.TIME = vio_item.optString("date");

                mItem.MONEY = vio_item.optString("money");

                mItem.FEN = vio_item.optString("fen");

                info.violationList.add(mItem);

            }

        }

        return info;

    }

    public static class Info{

        public String msg;

        public List<Violation> violationList = new ArrayList<>();

    }

    public static class Violation {

        public String TIME,AREA,ACT,MONEY,FEN;


    }
}
